package pl.javarsovia.javarsovia4android.activities;

import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
import pl.javarsovia.R;
import pl.javarsovia.javarsovia4android.activities.partners.PartnersTypeTabsCreator;
import pl.javarsovia.javarsovia4android.domain.Conference;
import pl.javarsovia.javarsovia4android.domain.ConferenceProvider;
import pl.javarsovia.javarsovia4android.domain.Partner;
import pl.javarsovia.javarsovia4android.domain.PartnerType;

import java.util.List;

/**
 * @author mgrzechocinski
 * @since 2010-06-13
 */
public class PartnersActivity extends TabActivity {
    private TabHost tabHost;

    private PartnersTypeTabsCreator partnersTypeTabsCreator;
    private Conference conference;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.partners);
        tabHost = getTabHost();
        conference = ConferenceProvider.getConference();
        partnersTypeTabsCreator = new PartnersTypeTabsCreator(tabHost, this);

        createTabsForEachPartnerType();
    }

    private void createTabsForEachPartnerType() {
        for (PartnerType type : PartnerType.values()) {
            createPartnerTypeTab(type);
        }
    }

    private void createPartnerTypeTab(PartnerType type) {
        List<Partner> partnersOfType = conference.getPartnersWithType(type);
        TabHost.TabSpec partnerTypeTab = partnersTypeTabsCreator.createPartnerTypeTab(type, partnersOfType);
        tabHost.addTab(partnerTypeTab);
    }
}
